#pragma once

#ifndef _MyLogger_H_
#define _MyLogger_H_
#ifdef WIN32
#pragma execution_character_set("utf-8")
#endif


#include <QApplication>
#include <QtWidgets>
#include <qmutex.h>
#include <qdatetime.h>
#include <QList>
#include <QFile>
#include <QString>

//using namespace std;

/// <summary>
/// 日志输出对象
/// </summary>
class MyLogger {

public:
	
	/// <summary>
	/// 输出debug信息
	/// </summary>
	/// <param name="msg"></param>
	/// <returns></returns>
	static void debug(QString msg);

	/// <summary>
	/// 输出info信息
	/// </summary>
	/// <param name="msg"></param>
	/// <returns></returns>
	static void info(QString msg);

	/// <summary>
	/// 输出warning信息
	/// </summary>
	/// <param name="msg"></param>
	/// <returns></returns>
	static void warning(QString msg);

	/// <summary>
	/// 输出error信息
	/// </summary>
	/// <param name="msg"></param>
	/// <returns></returns>
	static void error(QString msg);

	/// <summary>
	/// 获取实例
	/// </summary>
	/// <param name="logLevel"></param>
	/// <param name="filename"></param>
	/// <returns></returns>
	static void initLog(QString logLevel = "DEBUG", QString filename = "");

private:

	/// <summary>
	/// 初始化日志实例
	/// </summary>
	/// <param name="logLevel">指定输出日志的最小级别</param>
	/// <param name="filename">默认log文件名为程序启动时间命名的log文件</param>
	MyLogger();

	~MyLogger();

	MyLogger(const MyLogger& other) = delete;

	MyLogger operator=(const MyLogger& other) = delete;

	/// <summary>
	/// //默认调试级别为warning，即小于warning级别的都不会写入日志文件, 只有release版本的时候，才会输出到日志，debug版本正常输出到终端。
	/// </summary>
	/// <param name="type"></param>
	/// <param name="context"></param>
	/// <param name="msg"></param>
	static void customMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg);

private:

	//默认文件名为当前时间命名的log文件
	static QList<QtMsgType> m_levelList;
	
	//日志保存路径
	static QString m_logFile;
	
	//锁
	static QMutex m_logMutex;

};

#endif